/* 分公司二审修改页 */
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">分公司二审修改页</p>
      <table style="margin-bottom:20px" cellspacing="0" cellpadding="0" border="1" width="100%" ref="print">
        <tr>
          <th colspan="6">
            分公司二审修改
          </th>
        </tr>
        <tr>
          <td>
            修改人员
          </td>
          <td width="16.666%">
            {{info.Modifier}}
          </td>
          <td width="16.666%">
            分公司二审时间
          </td>
          <td width="16.666%">

          </td>
          <td width="16.666%">
            修改完成时间
          </td>
          <td width="16.666%">

          </td>
        </tr>
      </table>
      <table style="margin-bottom:20px" cellspacing="0" cellpadding="0" border="1" width="100%">
        <tr>
          <th>
            分公司二审修改清单
          </th>
        </tr>
        <tr>
          <td>
            <div style="width:99%;margin:auto;height:100%;">
              <Table style="border: none" border ref="selection" :columns="ershen" :data="info.data"></Table>
              <Row>
                <Col span="24" style="text-align: center;padding:10px">
                <Button type="primary" @click="passCS">通过二审</Button>
                </Col>
              </Row>
            </div>
          </td>
        </tr>
      </table>
      <table style="margin-bottom:20px" cellspacing="0" cellpadding="0" border="1" width="100%">
        <tr>
          <th colspan="4">
            分公司二审修改清单2
          </th>
        </tr>
        <tr>
          <td width="25%" class="ivu-table-cell">分公司二审人员</td>
          <td width="25%">{{info.audit}}</td>
          <td width="25%">分公司二审二次意见时间</td>
          <td width="25%">{{this.$moment().format('YYYY-MM-DD')}}</td>
        </tr>
        <tr>
          <td colspan="4">
            <div style="width:99%;margin:auto;height:100%;">
              <Table id="ershenXg" style="border: none" border ref="selection" :columns="ershenColumns" :data="ErshenXg" @on-row-click="getIndex"></Table>
              <Row>
                <Col span="24" style="text-align: center;padding:10px">
                <Button type="primary" @click="inputAdd('ErshenXg')">添加</Button>
                <Button type="error" @click="inputRemove('ErshenXg')">删除</Button>
                </Col>
              </Row>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            报告（正文、附图、附件、附表）
          </td>

          <td colspan="3">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
          </td>

        </tr>
      </table>

      <Row style="padding:40px 0">
        <Col span="12" style="text-align: left">
        <Button type="primary" @click="$print($refs.print)">打印</Button>
        </Col>
        <Col span="12" style="text-align: right;">
        <Button type="primary">保存</Button>
        <Button type="primary" @click="submit">发送意见</Button>
        </Col>
      </Row>
      <StepBar :status="4" />
    </Card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: {},
      query: [],
      ershenLoading: true,
      ErshenXg: [],
      ershen: [
        {
          align: "center",
          type: "selection",
          width: 60,
          align: "center"
        },
        {
          align: "center",
          width: 80,
          title: "序号",
          type: "index"
        },
        {
          align: "center",
          title: "二审意见",
          key: "Audit_opinion"
        },
        {
          align: "center",
          title: "修改说明",
          key: "Revise_explain"
        }
      ],
      ershenColumns: [
    
        {
          align: "center",
          title: "序号",
          type: "index",
          width: 80
        },
        {
          align: "center",
          title: "二审意见",
          key: "Audit_opinion",
          render: (h, { row, index }) => {
            return h("Input", {
              props: {
                type: "text",
                value: row.Audit_opinion
              },
              on: {
                "on-blur": val => {
                  this.ErshenXg[index].Audit_opinion = val.target.value;
                  console.log(
                    "失去焦点查看：" + this.ErshenXg[index].Audit_opinion
                  );
                }
              }
            });
          }
        },
        {
          align: "center",
          title: "修改说明",
          key: "Revise_explain"
        }
      ],
    };
  },
  mounted() {
    let query = this.$route.query;
    this.query = query;
    this.findByProject(query.Project_id, query.Atype);
  },
  methods: {
    inputAdd(type) {
      this.ErshenXg.push({});
    },
    inputRemove(type) {
        this[type].splice(this.allIndex, 1);
        console.log(this[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
    findByProject(Project_id, Atype) {
      axios
        .get("/audit/findByProject2", {
          params: {
            Atype,
            Project_id
          }
        })
        .then(res => {
          console.log(res);
          this.info = res;
          this.ershenLoading = false;
          console.log(res);
        });
    },
    submit() {
      let query = this.query;
      let AuditReplyLists = this.ErshenXg;
      for (let val of AuditReplyLists) {
        val["Audit_id"] = query.id;
        val["Audit_time"] = this.$moment().format("YYYY-MM-DD HH:mm:ss");
      }
      if (Object.keys(AuditReplyLists).length <= 0) {
        this.$Modal.error({
          title: "请输入意见"
        });
      } else {
        axios
          .get("/audit/isAuditb", {
            params: {
              Project_id: query.Project_id,
              Btype: query.Atype,
              OK: 1
            }
          })
          .then(res => {
            let title = res._MESSAGE;
            if (res._STATUS == 1) {
              this.$Modal.success({
                title: title + ": 请进入正在进行项目人员提交"
              });
              axios
                .post("/auditreply/saveOrUpdateM", {
                  AuditReplyLists
                })
                .then(res => {})
                .catch(err => {
                  this.$Modal.error({
                    title: "消息发送失败"
                  });
                });
            } else {
              this.$Modal.error({
                title
              });
            }
          });
      }
    },
    passCS() {
      axios
        .get("/audit/isAuditb", {
          params: {
            Project_id: this.$route.query.Project_id,
            Btype: this.$route.query.Atype,
            OK: 0
          }
        })
        .then(res => {
          let title = res._MESSAGE;
          if (res._STATUS == 1) {
            this.$Modal.success({
              title: title + ":通过初审进入正在进行操作"
            });
          } else {
            this.$Modal.error({
              title
            });
          }
        });
    }
  }
};
</script>

<style scoped>
#ershenXg {
  .ivu-input {
    border: none !important;
    height: 30px;

    input {
      outline: medium;
    }
  }
}
</style>